<template>
  <div class="complaint-wall">
    <div class="wall-header">
      <h1>校园吐槽墙</h1>
      <p>分享你的想法，吐槽校园生活</p>
    </div>
    
    <div class="wall-container">
      <!-- 左侧装饰 -->
      <div class="wall-decoration left">
        <div class="brick"></div>
        <div class="brick"></div>
        <div class="brick"></div>
      </div>
      
      <!-- 主内容区 -->
      <div class="wall-content">
        <el-form :model="form" label-width="auto" class="complaint-form">
          <div class="post-it-note">
            <el-form-item label="我想吐槽...">
              <el-input 
                v-model="form.goal" 
                type="textarea" 
                placeholder="今天食堂的菜太咸了..."
                :autosize="{ minRows: 4, maxRows: 6 }"
              />
            </el-form-item>
          </div>
          
          <div class="post-it-note yellow">
            <el-form-item label="如果能改进...">
              <el-input 
                v-model="form.reward" 
                type="textarea" 
                placeholder="希望食堂能少放点盐..."
                :autosize="{ minRows: 3, maxRows: 5 }"
              />
            </el-form-item>
          </div>
          
          <div class="post-it-note pink">
            <el-form-item label="不然的话...">
              <el-input 
                v-model="form.punishment" 
                type="textarea" 
                placeholder="我只能天天点外卖了..."
                :autosize="{ minRows: 3, maxRows: 5 }"
              />
            </el-form-item>
          </div>
          
          <el-button 
            type="primary" 
            @click="onSubmit" 
            class="submit-btn"
            icon="el-icon-upload"
          >
            贴到墙上
          </el-button>
        </el-form>
      </div>
      
      <!-- 右侧装饰 -->
      <div class="wall-decoration right">
        <div class="brick"></div>
        <div class="brick"></div>
        <div class="brick"></div>
      </div>
    </div>
    
    <!-- 已有吐槽展示区 -->
    <div class="wall-posts" v-if="posts.length > 0">
      <div 
        v-for="(post, index) in posts" 
        :key="index"
        class="post-it-note"
        :class="getRandomColor()"
      >
        <div class="post-content">
          <h3>我想吐槽...</h3>
          <p>{{ post.goal }}</p>
          <h3>如果能改进...</h3>
          <p>{{ post.reward }}</p>
          <h3>不然的话...</h3>
          <p>{{ post.punishment }}</p>
          <div class="post-meta">
            <span class="post-time">{{ formatTime(post.timestamp) }}</span>
            <div class="post-actions">
              <el-button 
                type="text" 
                @click="toggleLike(index)"
                :class="{ 'liked': post.isLiked }"
              >
                <i class="el-icon-star-off"></i>
                {{ post.likes || 0 }}
              </el-button>
              <el-button 
                type="text" 
                @click="showComments(index)"
              >
                <i class="el-icon-chat-dot-round"></i>
                {{ post.comments ? post.comments.length : 0 }}
              </el-button>
            </div>
          </div>
          
          <!-- 评论区 -->
          <div class="comments-section" v-if="post.showComments">
            <div class="comments-list" v-if="post.comments && post.comments.length > 0">
              <div v-for="(comment, commentIndex) in post.comments" 
                   :key="commentIndex" 
                   class="comment-item"
              >
                <div class="comment-content">
                  <span class="comment-user">{{ comment.user }}</span>
                  <p>{{ comment.content }}</p>
                  <span class="comment-time">{{ formatTime(comment.timestamp) }}</span>
                </div>
              </div>
            </div>
            
            <div class="comment-form">
              <el-input
                v-model="post.newComment"
                type="textarea"
                :rows="2"
                placeholder="写下你的评论..."
              />
              <el-button 
                type="primary" 
                size="small" 
                @click="submitComment(index)"
                :disabled="!post.newComment"
              >
                发表评论
              </el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ComplaintWall',
  data() {
    return {
      form: {
        goal: '',
        reward: '',
        punishment: ''
      },
      posts: [],
      colors: ['yellow', 'pink', 'blue', 'green'],
      currentUser: '匿名用户' // 这里可以替换为实际的用户系统
    }
  },
  methods: {
    onSubmit() {
      if (!this.form.goal || !this.form.reward || !this.form.punishment) {
        this.$message.warning('请填写完整信息！')
        return
      }
      
      const newPost = {
        ...this.form,
        timestamp: new Date().getTime(),
        likes: 0,
        isLiked: false,
        comments: [],
        showComments: false,
        newComment: ''
      }
      
      this.posts.unshift(newPost)
      this.form = {
        goal: '',
        reward: '',
        punishment: ''
      }
      
      this.$message.success('吐槽成功！')
    },
    toggleLike(index) {
      const post = this.posts[index]
      post.isLiked = !post.isLiked
      post.likes = post.isLiked ? (post.likes || 0) + 1 : (post.likes || 1) - 1
    },
    showComments(index) {
      this.posts[index].showComments = !this.posts[index].showComments
    },
    submitComment(index) {
      const post = this.posts[index]
      if (!post.newComment.trim()) return
      
      if (!post.comments) {
        post.comments = []
      }
      
      post.comments.push({
        user: this.currentUser,
        content: post.newComment,
        timestamp: new Date().getTime()
      })
      
      post.newComment = ''
      this.$message.success('评论成功！')
    },
    getRandomColor() {
      return this.colors[Math.floor(Math.random() * this.colors.length)]
    },
    formatTime(timestamp) {
      const date = new Date(timestamp)
      return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
    }
  }
}
</script>

<style scoped>
.complaint-wall {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.wall-header {
  text-align: center;
  margin-bottom: 40px;
}

.wall-header h1 {
  font-size: 2.5em;
  color: #333;
  margin-bottom: 10px;
}

.wall-header p {
  color: #666;
  font-size: 1.2em;
}

.wall-container {
  display: flex;
  gap: 20px;
  margin-bottom: 40px;
}

.wall-decoration {
  width: 60px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.brick {
  height: 30px;
  background: #8B4513;
  border-radius: 4px;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.wall-content {
  flex: 1;
}

.complaint-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.post-it-note {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  transform: rotate(-1deg);
  transition: transform 0.3s ease;
}

.post-it-note:hover {
  transform: rotate(0deg) scale(1.02);
}

.post-it-note.yellow {
  background: #FFEB3B;
}

.post-it-note.pink {
  background: #FFCDD2;
}

.post-it-note.blue {
  background: #BBDEFB;
}

.post-it-note.green {
  background: #C8E6C9;
}

.submit-btn {
  align-self: flex-end;
  margin-top: 20px;
}

.wall-posts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  padding: 20px;
}

.post-content {
  h3 {
    font-size: 1.1em;
    margin: 10px 0 5px;
    color: #333;
  }
  
  p {
    margin: 0 0 15px;
    color: #666;
    line-height: 1.5;
  }
}

.post-meta {
  margin-top: 15px;
  font-size: 0.9em;
  color: #999;
}

.post-time {
  font-style: italic;
}

.post-actions {
  display: flex;
  gap: 15px;
  margin-top: 10px;
}

.post-actions .el-button {
  padding: 0;
  font-size: 14px;
}

.post-actions .liked {
  color: #409EFF;
}

.comments-section {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #eee;
}

.comments-list {
  margin-bottom: 15px;
}

.comment-item {
  margin-bottom: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 4px;
}

.comment-content {
  .comment-user {
    font-weight: bold;
    color: #409EFF;
    margin-right: 10px;
  }
  
  p {
    margin: 5px 0;
    color: #666;
  }
  
  .comment-time {
    font-size: 12px;
    color: #999;
  }
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  
  .el-button {
    align-self: flex-end;
  }
}
</style> 